﻿using System;
using FluentNHibernate.Conventions;
using FluentNHibernate.Conventions.Instances;

namespace NHibernate.Sidekick.Utils.MappingConventions
{
    ///<summary>
    /// Maps <see cref="System.DateTime"/> to Oracle's 'date' type instead of 'timestamp(4)'.
    ///</summary>
    public class OracleDateTimeTypeConvention : IPropertyConvention
    {
        /// <summary>
        /// Apply changes to the target.
        /// </summary>
        /// <param name="instance"></param>
        public void Apply(IPropertyInstance instance)
        {
            if (instance.Property.PropertyType.FullName == typeof(DateTime).FullName)
            {
                instance.CustomSqlType("date");
            } 
        }
    }
}